from Tkconstants import END
from tkFileDialog import askdirectory, asksaveasfile
import Tkinter

class tkMain:
    def __init__(self, master):
        
        global root, history_frame, info_line
        
        root = master
        root.title('Source code line counter tool TK Shell')
        
        LEFT, Label = Tkinter.LEFT, Tkinter.Label # shortcut names
        
        frame_path_source_root = Tkinter.Frame(root)
        frame_path_source_root.pack(fill=Tkinter.X, side=Tkinter.TOP)
        Label(frame_path_source_root, text="Source root:", width=10).pack(side=LEFT)
        self.text_path_source = Tkinter.Entry(frame_path_source_root, width = 50)
        self.text_path_source.pack(side=LEFT)
        Tkinter.Button(frame_path_source_root, text="Browse", command = self.getPath).pack(side=LEFT)
        
        frame_path_report = Tkinter.Frame(root)
        frame_path_report.pack(fill=Tkinter.X, side=Tkinter.TOP, pady=2)
        Label(frame_path_report, text="Report path:", width=10).pack(side=LEFT)
        self.text_path_report = Tkinter.Entry(frame_path_report, width = 50)
        self.text_path_report.pack(side=LEFT)
        Tkinter.Button(frame_path_report, text="Browse", command = self.get_report_path).pack(side=LEFT)
        
        
    #    init_vars()

        #-- Create the history frame (to be filled in during runtime)
        history_frame = Tkinter.Frame(root)
        history_frame.pack(fill=Tkinter.X, side=Tkinter.BOTTOM, pady=2)
        #-- Create the info frame and fill with initial contents
        info_frame = Tkinter.Frame(root)
        info_frame.pack(fill=Tkinter.X, side=Tkinter.BOTTOM)
        # first put the column labels in a sub-frame
        
        label_line = Tkinter.Frame(info_frame, relief=Tkinter.RAISED, borderwidth=1)
        label_line.pack(side=Tkinter.TOP, padx=2, pady=1)
        Label(label_line, text="Run #", width=5).pack(side=LEFT)
        Label(label_line, text="Source:", width=20).pack(side=LEFT)
        Label(label_line, text="Target:", width=20).pack(side=LEFT)
        Label(label_line, text="Type:", width=20).pack(side=LEFT)
        Label(label_line, text="Proxy Mode:", width=20).pack(side=LEFT)
        # then put the "next run" information in a sub-frame
     
        info_line = Tkinter.Frame(info_frame)
        info_line.pack(side=Tkinter.TOP, padx=2, pady=1)
        
        Tkinter.Button(text="Counter", command = self.counter).pack(side=LEFT)
        
    #    update_specs()
        #-- Finally, let's actually do all that stuff created above
        root.mainloop()
        
    def getPath(self):
        path = askdirectory();
        self.text_path_source.delete(0, END)
        self.text_path_source.insert(0, path)
        
    def get_report_path(self):
        path = asksaveasfile();
        self.text_path_report.delete(0, END)
        self.text_path_report.insert(0, path)
        
    def counter(self):
        pass
    
    
def run():
    top = Tkinter.Tk()
    tkMain(top)
    top.mainloop()